package com.mycompany.tpfinal.abm;

import java.io.FileInputStream;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.util.Properties;
import javax.swing.JOptionPane;


public class Conexion {
    private static String baseUtilizada;
    private  static String user;
    private   static String pass;
    private   static String url;
    private   static Connection conn;

    public Conexion() {
    }
        
    
    
    
    public static Connection obtieneConexion() throws IOException{
        Properties propiedades = new Properties();
        FileInputStream archivo = new FileInputStream("C:\\Users\\Juan\\Documents\\NetBeansProjects\\tpfinal-abm\\src\\main\\resources\\configuracion.properties");
        propiedades.load(archivo);
        
        baseUtilizada = propiedades.getProperty("baseUtilizada");
        
        if(baseUtilizada.equals("mysql")){
            
            url = propiedades.getProperty("urlmysql");
            user =  propiedades.getProperty("user");
            pass = propiedades.getProperty("pass");
                
            try{
            Class.forName("com.mysql.jdbc.Driver");
            conn = DriverManager.getConnection(url,user,pass);
            
        }catch(Exception ex){
            JOptionPane.showMessageDialog(null, "Error" + ex.getMessage());
        }
       }
       
        if(baseUtilizada.equals("hsql")){
            url = propiedades.getProperty("urlhsql");
            try{
            Class.forName("org.hsqldb.jdbcDriver");
            conn = DriverManager.getConnection(url);
            
            
        }catch(Exception ex){
            JOptionPane.showMessageDialog(null, "Error" + ex.getMessage());
        }
       }
        
        return conn;
        
    }
    

}
